package com.wwz.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wwz.entity.Company;
import com.wwz.entity.Result;
import com.wwz.exception.EcoBootException;
import com.wwz.query.CompanyQuery;
import com.wwz.service.ICompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("company")
@Api(tags = "公司控制器")
public class CompanyController {
    @Resource
    private ICompanyService companyService;

    @GetMapping("toPage")
    @ApiOperation("分页查询")
    public Result toPage(CompanyQuery query){
        IPage<Company> toPage = companyService.toPage(query);
        return Result.ok(toPage);
    }

    @PostMapping("addOrUpData")
    @ApiOperation("添加或修改")
    public Result addOrUpData(@RequestBody Company company){
        companyService.addOrUpData(company);
        return Result.ok("操作成功");
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除")
    public Result delete(@PathVariable("id") String id){
        companyService.deleteById(id);
        return Result.ok("删除成功");
    }
}
